package nacos

import (
	"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client"
	"github.com/nacos-group/nacos-sdk-go/v2/vo"
)

type NacosRegistryServer struct {
	Client      naming_client.INamingClient
	ServiceName string
	Ip          string
	Port        uint64
	Weight      float64
	Enable      bool
	Health      bool
}

func (s *NacosRegistryServer) UnRegister() {
	_, err := s.Client.DeregisterInstance(vo.DeregisterInstanceParam{
		ServiceName: s.ServiceName,
		Ip:          s.Ip,
		Port:        s.Port,
		Ephemeral:   true,
	})
	if err != nil {

	}
}

func (s *NacosRegistryServer) Register() {
	_, err := s.Client.RegisterInstance(vo.RegisterInstanceParam{
		ServiceName: s.ServiceName,
		Ip:          s.Ip,
		Port:        s.Port,
		Weight:      s.Weight,
		Enable:      true,
		Healthy:     true,
		Ephemeral:   true,
		Metadata:    map[string]string{"weight": "20"},
	})
	if err != nil {
		panic(err)
	}
}
